package com.shirley.netty.websocket.client;

import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.handler.codec.http.HttpClientCodec;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketClientCompressionHandler;

public class WebsocketClientChannel extends ChannelInitializer {

    private WebSocketClientHandler webSocketClientHandler;
    public WebsocketClientChannel(WebSocketClientHandler webSocketClientHandler) {
        this.webSocketClientHandler = webSocketClientHandler;
    }

    @Override
    protected void initChannel(Channel ch) throws Exception {

        ch.pipeline().addLast(new HttpClientCodec())
                .addLast(new HttpObjectAggregator(8192))
                .addLast(WebSocketClientCompressionHandler.INSTANCE)
                .addLast(webSocketClientHandler);
    }
}
